<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp" %>

<head>
    <title><spring:message code="sp.placeorder.title"/></title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <link rel="stylesheet" href="<c:url value="/css/styles.css"/>"/>
    <script src="<c:url value="/javascripts/common.js"/>" type="text/javascript"></script>
</head>

<body>
<div class="page">
<%@include file="../top_menu.jsp" %>
<table
        width=100%>
    <tr>
        <td>
            <%@include
                    file="/WEB-INF/jsp/serviceprovider/order/place_orders_menu.jsp" %>
            <br/>
        </td>
    </tr>
    <tr>
        <td>
            <%@include file="/WEB-INF/jsp/include/messages.jsp" %>
            <br/>
        </td>
    </tr>

</table>
<div class="contentArea"><c:choose>
<c:when test="${empty shippingList}">
    <div align="center">
        <table width="300">
            <tr>
                <td class="error"><spring:message code="sp.placeorder.label.noshippingmodesfound"/>.</td>
            </tr>
        </table>
    </div>
</c:when>
<c:otherwise>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr>
    <td valign="top"></td>
    <td valign="top">
        <form:form method="post" commandName="placeOrderVO">
            <table border=0 cellpadding=0 cellspacing=0 width=100%>
                <tr>
                    <td colspan="2">
                        <%@include
                                file="/WEB-INF/jsp/include/header.jsp" %>
                    </td>
                </tr>
                <tr>
                    <td colspan="2"><c:import
                            url="/WEB-INF/jsp/include/provider.jsp"/></td>
                </tr>


                <tr>
                    <td>
                        <h5><spring:message code="sp.placeorder.label.placeorder"/></h5>
                    </td>
                    <td align="right">
                    </td>
                </tr>
            </table>

            <c:if test="${placeOrderVO.hasNewTransactions}">
                <table>
                    <tr>
                        <th class="green" colspan="2"><spring:message
                                code="sp.placeorder.label.yousitllhaveunprocessedtransactionstext"/>.
                        </th>
                    </tr>
                </table>
                <br/>
            </c:if>

            <c:forEach var="batch" items="${placeOrderVO.batchList}" varStatus="b">
                <c:set var="tr_countInBatch"
                       value="${fn:length(batch.transactions)}"/>
                <c:if test="${tr_countInBatch>0}">
                    <table width=98% class="formTable" style="border-color: black">
                        <tr class="formHeader" style="border-color: black">
                            <td colspan="18">
                                <form:checkbox path="batchList[${b.index}].includedInOrder"/>&nbsp;
                                <form:hidden path="batchList[${b.index}].id"/>
                                <spring:message code="sp.placeorder.label.batch"/> ${batch.id} -
                                <spring:message code="sp.placeorder.label.approvedon"/>
                                <form:input path="batchList[${b.index}].batchDate" disabled="true" cssClass="formHeader"
                                            cssStyle="border: 0;"/></td>
                        </tr>
                        <tr>
                            <th style="text-align:center" rowspan="3"><spring:message
                                    code="sp.placeorder.label.ser"/></th>
                            <th style="text-align:center" rowspan="3"><spring:message
                                    code="sp.placeorder.label.ssn"/></th>
                            <th style="text-align:center" rowspan="3"><spring:message
                                    code="sp.placeorder.label.customername"/></th>
                            <th style="text-align:center" rowspan="3"><spring:message
                                    code="sp.placeorder.label.amountreceived"/></th>
                            <th colspan="${fn:length(batch.payeeMap) + 2}"
                                style="text-align: center;"><spring:message
                                    code="sp.placeorder.label.miscellanceouspayment"/></th>
                            <th style="text-align:center" rowspan="3"><spring:message
                                    code="sp.placeorder.label.customerbalance"/></th>
                        </tr>
                        <tr>
                            <th style="text-align:center" rowspan="2"><spring:message
                                    code="sp.placeorder.label.svcfee"/></th>
                            <th style="text-align:center" rowspan="2"><spring:message
                                    code="sp.placeorder.label.selffee"/></th>

                        </tr>

                        <tr><!-- Payee Names -->
                            <c:forEach var="payee" items="${batch.payeeMap}">
                                <th style="text-align:center">${payee.value}
                                    <form:hidden path="batchList[${b.index}].payeeMap[${payee.key}]"/></th>
                            </c:forEach>
                        </tr>

                        <tbody>
                        <c:forEach var="transaction" items="${batch.transactions}"
                                   varStatus="i">
                            <tr>
                                <td>${transaction.value.id}</td>
                                <form:hidden path="batchList[${b.index}].transactions[${transaction.key}].id"/>
                                <td>${transaction.value.customerSSN}</td>
                                <form:hidden path="batchList[${b.index}].transactions[${transaction.key}].customerSSN"/>
                                <td>${transaction.value.customerName}</td>
                                <form:hidden
                                        path="batchList[${b.index}].transactions[${transaction.key}].customerName"/>
                                <td><form:input disabled="true"
                                                path="batchList[${b.index}].transactions[${transaction.key}].amount"
                                                cssClass="disabled"/>
                                    <form:hidden
                                            path="batchList[${b.index}].transactions[${transaction.key}].amount"/></td>
                                <td><form:input disabled="true"
                                                path="batchList[${b.index}].transactions[${transaction.key}].serviceFee"
                                                cssClass="disabled"/>
                                    <form:hidden
                                            path="batchList[${b.index}].transactions[${transaction.key}].serviceFee"/></td>
                                <td><form:input disabled="true"
                                                path="batchList[${b.index}].transactions[${transaction.key}].selfFee"
                                                cssClass="disabled"/>
                                    <form:hidden
                                            path="batchList[${b.index}].transactions[${transaction.key}].selfFee"/></td>
                                <c:forEach var="payee" items="${batch.payeeMap}" varStatus="p">
                                    <td><form:input
                                            path="batchList[${b.index}].transactions[${transaction.key}].amounts[${payee.key}]"
                                            cssClass="disabled"
                                            disabled="true"/>
                                        <form:hidden
                                                path="batchList[${b.index}].transactions[${transaction.key}].amounts[${payee.key}]"/></td>
                                </c:forEach>
                                <td><form:input disabled="true"
                                                path="batchList[${b.index}].transactions[${transaction.key}].customerBalance"
                                                cssClass="disabled"/>
                                    <form:hidden
                                            path="batchList[${b.index}].transactions[${transaction.key}].customerBalance"/></td>
                            </tr>
                        </c:forEach>
                        </tbody>
                        <tfoot>
                        <tr>
                            <th colspan="12"><spring:message code="sp.placeorder.label.notes"/></th>
                        </tr>
                        </tfoot>
                    </table>
                </c:if>
            </c:forEach>

            <c:if test="${not empty placeOrderVO.batchList}">
                <table>
                    <tr>
                        <th class="green" colspan="2"><spring:message
                                code="sp.placeorder.label.ifyouwanttochangepayeetext"/>.
                        </th>
                    </tr>
                </table>
                <c:if test="${not placeOrderVO.hasNewTransactions}">
                    <table width=98% class="formTable">
                        <tr class="formHeader">
                            <td colspan="2"><spring:message code="sp.placeorder.label.orderdetails"/></td>
                        </tr>
                        <tr>
                            <th valign="top" class="green"><spring:message
                                    code="sp.placeorder.label.ordername"/>:<br>

                            </th>
                            <th><form:input path="orderName" maxlength="100" size="38"/><br>
                                <form:errors path="orderName" cssClass="errors"/>
                            </th>
                        </tr>
                        <tr>
                            <th valign="top" class="green"><spring:message
                                    code="sp.placeorder.label.shippingmode"/></th>
                            <th><form:select path="shippingMode">
                                <form:options items="${shippingList}" itemValue="id" itemLabel="mode"/>
                            </form:select></th>
                        </tr>

                        <tr>
                            <th valign="top" class="green"><spring:message
                                    code="sp.placeorder.label.shippingtips"/></th>
                            <th><form:input path="shippingTips" maxlength="100" size="38"/></th>
                        </tr>
                        <tr>
                            <th valign="top" class="green"><spring:message
                                    code="sp.placeorder.label.shpecialshippinginstructions"/></th>
                            <th><form:textarea rows="5" cols="40" path="shippingInstructions"/></th>
                        </tr>


                    </table>
                </c:if>
                <table>
                    <tr>
                        <th class="green" colspan="2"><spring:message
                                code="sp.placeorder.label.thisisyourlastchancetext"/>.
                        </th>
                    </tr>
                    <tr>
                        <th>
                            <c:if test="${not placeOrderVO.hasNewTransactions}">
                                <input type="submit" name="place_order"
                                       class='ui-button ui-state-default ui-corner-all'
                                       value="<spring:message code="sp.placeorder.button.placeorder" />"/>
                            </c:if>
                            <input type="submit" name="revert_transactions"
                                   class='ui-button ui-state-default ui-corner-all'
                                   value="<spring:message code="sp.placeorder.button.movebacktonew"/>"/>
                        </th>
                    </tr>
                </table>


            </c:if>
            <c:if test="${empty placeOrderVO.batchList}">
                <table>
                    <tr>
                        <th class="green" colspan="2"><spring:message
                                code="sp.placeorder.label.therearenotransactionstext"/></th>
                    </tr>

                </table>
            </c:if>
            <button name='back_to_new_transaction'
                    class='ui-button ui-state-default ui-corner-all'
                    style="padding: 3px"><spring:message
                    code="sp.placeorder.button.gotonewtransaction"/></button>
        </form:form></td>
</tr>
</table>
</c:otherwise>
</c:choose></div>
</div>
<%@include file="/WEB-INF/jsp/include/footer.jsp" %>
</body>
</html>